package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.GwContractDetailMapper;
import com.ruoyi.system.domain.GwContractDetail;
import com.ruoyi.system.service.IGwContractDetailService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 合同详情Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-08
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class GwContractDetailServiceImpl implements IGwContractDetailService {

    @Resource
    private GwContractDetailMapper gwContractDetailMapper;

    /**
     * 查询合同详情
     *
     * @param id 合同详情主键
     * @return 合同详情
     */
    @Override
    public GwContractDetail selectGwContractDetailById(String id) {
        return gwContractDetailMapper.selectGwContractDetailById(id);
    }

    /**
     * 查询合同详情列表
     *
     * @param gwContractDetail 合同详情
     * @return 合同详情
     */
    @Override
    public List<GwContractDetail> selectGwContractDetailList(GwContractDetail gwContractDetail) {
        return gwContractDetailMapper.selectGwContractDetailList(gwContractDetail);
    }

    /**
     * 新增合同详情
     *
     * @param gwContractDetail 合同详情
     * @return 结果
     */
    @Override
    public int insertGwContractDetail(GwContractDetail gwContractDetail) {
        gwContractDetail.setId(IdUtils.fastSimpleUUID());
        gwContractDetail.setCreateTime(DateUtils.getNowDate());
        gwContractDetail.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        gwContractDetail.setUpdateTime(DateUtils.getNowDate());
        gwContractDetail.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        return gwContractDetailMapper.insertGwContractDetail(gwContractDetail);
    }

    /**
     * 修改合同详情
     *
     * @param gwContractDetail 合同详情
     * @return 结果
     */
    @Override
    public int updateGwContractDetail(GwContractDetail gwContractDetail) {
        gwContractDetail.setUpdateTime(DateUtils.getNowDate());
        gwContractDetail.setUpdateBy(SecurityUtils.getUsername());
        return gwContractDetailMapper.updateGwContractDetail(gwContractDetail);
    }

    /**
     * 批量删除合同详情
     *
     * @param ids 需要删除的合同详情主键
     * @return 结果
     */
    @Override
    public int deleteGwContractDetailByIds(String[] ids) {
        return gwContractDetailMapper.deleteGwContractDetailByIds(ids);
    }

    /**
     * 删除合同详情信息
     *
     * @param id 合同详情主键
     * @return 结果
     */
    @Override
    public int deleteGwContractDetailById(String id) {
        return gwContractDetailMapper.deleteGwContractDetailById(id);
    }

    @Override
    public int updateStatusByContractIdAndNameAndTel(String contractId, String phoneNumber, String approveStatus, String approveMessage) {
        return gwContractDetailMapper.updateStatusByContractIdAndNameAndTel(contractId, phoneNumber, approveStatus, approveMessage);
    }

    @Override
    public void deleteGwContractDetailByMainId(String id) {
        gwContractDetailMapper.deleteGwContractDetailByMainId(id);
    }
}
